package syyrjx.controller;

import syyrjx.jdbc.DataBase;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class UserPageServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.userInfo(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.userInfo(request, response);
    }

    private void userInfo(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String userpwd = request.getParameter("userpwd");
        if(DataBase.logIn(username,userpwd)){
            request.getSession();//派发令牌
            response.sendRedirect("http://localhost:8080/onlineSystem/index.html");
        }else{
            response.sendRedirect("http://localhost:8080/onlineSystem/logFalse.html");
        }
    }
}
